///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package org.tyemill.utils
{
import flash.events.ErrorEvent;

/**
 * General Assert.
 * 
 * <p>In compiler settings: <i>-define+=CONFIG::debugging,true</i> enables 
 * Assert for those using a debug version of the Flash Player. To turn off, 
 * and avoid the compiler error for not defining debugging - replace ',true' 
 * with ',false'.</p>
 */
public class Assert extends ErrorEvent
{
	/** Standard <code>false</code> message. **/
	public static const FALSE:String = "required true";
	
	/** Standard <code>true</code> message. **/
	public static const TRUE:String = "required false";
	
	/** Constructor.
	 * @param type
	 * The type of Assert Error.
	 * @param bubbles
	 * <code>false</code> if the event does not bubble (default).
	 * @param cancelable
	 * <code>false if the event is not cancelable (default).
	 * @param text
	 * The message to provide with the Assert.
	 * @param id
	 * The error id.
	 */
	public function Assert(type:String, bubbles:Boolean=false, 
	cancelable:Boolean=false, text:String="Assert", id:int=-1)
	{
		super(type, bubbles, cancelable, text, id);
	}
	
	/** Checks to make sure the condition provided is true. 
	 * @param condition
	 * The condition evaluated.
	 * @param messate 
	 * The message to report in the event of a bad condition.
	 * 
	 * @throws org.tyemill.utils.Assert
	 * If the conditional is <code>false</code>.
	 * @return The result of the conditional (<code>true</code> if 
	 * conditional is <code>true</code>).
	 ***/
	public static function isTrue(condition:Boolean, 
	message:String = null):Boolean
	{
		CONFIG::debugging 
		{
			if(!condition)
			{
				if(!message) throw new Assert(Assert.FALSE, false, false);
				else throw new Assert(Assert.FALSE, false, false, message);
			}
		}
		
		return condition;
	}
	
	/** Checks to make sure the condition provided is false. 
	 * @param condition
	 * The condition evaluated.
	 * @param messate 
	 * The message to report in the event of a bad condition.
	 * 
	 * @throws org.tyemill.utils.Assert
	 * If the conditional is <code>true</code>.
	 * @return The result of the conditional (<code>true</code> if 
	 * conditional is <code>true</code>).
	 ***/
	public static function isFalse(condition:Boolean,
	message:String = null):Boolean
	{
		CONFIG::debugging 
		{
			if(condition)
			{
				if(!message) throw new Assert(Assert.TRUE, false, false);
				else throw new Assert(Assert.TRUE, false, false, message);
			}
		}
		
		return condition;
	}
	
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //